<template>
	<view>
		<cu-custom bgColor="bg-gradual-blue" :isBack="true">
			<block slot="backText">
				返回
			</block>
			<block slot="content">我的订阅</block>
		</cu-custom>

		<view v-if="subscribes.length > 0" @click="sendMsg(subscribe)" v-for="(subscribe, index) in subscribes" class="bg-white zaiui-subscribe-card-view cu-card shadow-warp">
			<view class="flex text-black text-lg">
				<view class="flex-sub text-left flex align-end">
					气象
					<view class="text-sm text-color-base margin-left-xs">天气预报</view>
				</view>
			</view>
			<view class="text-gray margin-top margin-bottom">如果某天的明天下雨，将在今天的晚上9点钟提醒您。推送方式：邮箱、小程序订阅消息</view>
			<view class="zaiui-line-view" />
			<view class="zaiui-right-view">
				<text class="cuIcon-write text-blue" @tap.stop="toAddress(1, subscribe)">编辑</text>
				<text class="cuIcon-delete" @tap.stop="delAdress(subscribe)" style="color: red;">删除</text>
			</view>
		</view>
		<view v-if="subscribes.length == 0" style="height: 500rpx;width: 100%;display: flex;justify-content: center;align-items: center;flex-direction: column;">
			<u-icon name="order" color="#ababab" size="300"></u-icon>
			<view class="margin-top">还没有添加任何地址，快去添加吧 ~</view>
		</view>

		<!--按钮-->
		<view class="wecanui-footer-fixed foot-pb">
			<view class="flex flex-direction"><button style="height: 70rpx;" class="cu-btn bg-blue shadow-blur round" @tap="toAddress(0)">添加新地址</button></view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			subscribes: [{}, {}, {}]
		};
	},
	methods: {
		delAdress(subscribe) {
			uni.showModal({
				title: '提示',
				content: '确定要删除“ ' + subscribe.subscribe + ' ' + (subscribe.fullAddress == null ? '' : subscribe.fullAddress) + ' ”这个地址吗？',
				success: res => {
					if (res.cancel != true) {
						this.$api.deleteAddress({
							data: {
								id: subscribe.id
							},
							success: res => {
								if (res.data.code == 200) {
									uni.showToast({
										title: '删除成功',
										icon: 'success'
									});
									this.getAddressList();
								}
							},
							complete: data => {}
						});
					}
				}
			});
		},
		getAddressList() {
			uni.showLoading({
				title: '加载中',
				mask: true
			});
			this.$api.getAddressList({
				data: {},
				success: res => {
					if (res.data.code == 200) {
						this.subscribes = res.data.data;
					}
				},
				complete: data => {
					uni.hideLoading();
				}
			});
		}
	}
};
</script>

<style lang="scss">
.zaiui-subscribe-card-view {
	position: relative;
	margin: 36.36rpx 27.27rpx;
	border-radius: 10.9rpx;
	padding: 18.18rpx;

	.zaiui-line-view {
		position: relative;
		background: #f9f9f9;
		margin-bottom: 20rpx;
		height: 2rpx;
	}

	.zaiui-right-view {
		position: relative;
		text-align: right;

		text {
			&:before {
				margin-right: 5px;
			}
		}

		text + text {
			margin-left: 20px;
		}
	}
}

.wecanui-footer-fixed .flex-direction {
	padding: 18.18rpx;
}
</style>
